package com.winbomb.kingcard.base.anim.impl;

import com.winbomb.kingcard.Assets;
import com.winbomb.kingcard.IGameLogic;
import com.winbomb.kingcard.Pos;
import com.winbomb.kingcard.base.BattleState;
import com.winbomb.kingcard.base.GameLogic;
import com.winbomb.kingcard.base.anim.IPlayable;
import com.winbomb.kingcard.base.anim.SimpleAnimation;
import com.winbomb.kingcard.framework.Graphics;

public class BattleAnim implements IPlayable {

	private SimpleAnimation anim;
	private Graphics g;
	private IGameLogic game;
	private Pos tgPos;

	public BattleAnim(IGameLogic game) {
		this.game = game;
		this.g = ((GameLogic) game).getRender().getGraphics();

		anim = new SimpleAnimation();
		anim.setDuration(5000);
		anim.setFrameCount(8);
	}

	@Override
	public boolean play(float dt) {
		if (!anim.hasFinished()) {

			int frameNum = anim.getCurrFrame();
			g.drawPixmap(Assets.fight, tgPos.x, tgPos.y, 75 * frameNum, 0, 75, 80);
			anim.step(dt);

			return (game.getState() == BattleState.BATTLE_END);
		}

		return true;
	}

	public void setTargetPos(Pos tgPos) {
		this.tgPos = tgPos;
	}

	public void reset() {
		anim.reset();
		tgPos = null;
	}
}
